$(function(){
	//setInterval("current()",1000);
		
	//this for layout
	var outerLayout, innerLayout; 
	outerLayout = $('body').layout({ 
		center__paneSelector:	".outer-center" ,
		west__paneSelector:		".outer-west" ,
		west__size:				200 ,
		north__size:			105,
		north__spacing_open:	5,
		north__spacing_closed:	12,
		west__spacing_open:		5,
		west__spacing_closed:	12,
		south__spacing_open:	0,
		north__resizable:		false,
		west__resizable:		false,
		togglerTip_closed:		"打开"
		//center_onresize:		"innerLayout.resizeAll" 
	}); 
	innerLayout = $('div.outer-center').layout({ 
		center__paneSelector:	".inner-center" ,
		north__paneSelector:	".inner-north" ,
		north__size:			30,
		spacing_open:	0,
		spacing_closed:	0
	}); 
	
	//this for link for title
	$("#shownavlink").html($("#navlink").text());
	
	//this for all button
	$( "input[type=submit] , input[type=reset] , input[type=button]" ).button().css({"font-size":"12px","padding":"3px 8px","color":"#000"});

	//this for page
	showpage();
	
	$("#main_menu").accordion({ collapsible:true,autoHeight:false,heightStyle: "content"} );
	$("#main_menu").find("li a").click(function(){
		if($(this).attr("href").length>0){
			location.href=$(this).attr("href");
		}
	});
	
	//for datepicker
	$.datepicker.setDefaults($.datepicker.regional['zh-CN']);
	$('.datepicker').datetimepicker({
		dateFormat: "yy-mm-dd",
		showTimepicker: false,changeMonth: true,changeYear: true
	});
	
	//mouse track
	$('td').hover( 
		function(){$(this).addClass("table_td_hover");}, 
		function(){$(this).removeClass("table_td_hover");} 
	);
	$('tr').hover( 
		function(){$(this).addClass("table_tr_hover");}, 
		function(){$(this).removeClass("table_tr_hover");} 
	);
//	loadpage();
});

//validator 默认选项
$.validator.setDefaults({
    onkeyup  : true,
    onclick  : true,
    onfocusout : true,
    errorLabelContainer:"#msg",
    wrapper:"li",
    highlight:function(){}
});



//ajax 调用方法
function AjaxCore(params,thisaction,jump){
	$.ajax({
		url : thisaction,type : "post",dataType:"json",data : params,timeout : 20000,// 设置请求超时时间（毫秒）。
		beforeSend: function(XMLHttpRequest){
			$("#msg").show();
			$("#msg").html("Loading...");
		},
		success : function(data) {
			if (data.flag == true) {
				window.location.href =jump;
			}else{
				$("#msg").show();
				$("#msg").html(data.result);
				shock("#msg");
			}
		}
	});
}

//ajax 左右晃动
function shock(id){		
	var speed=50;
	$(id).animate({'margin': '0 30px 0 -30px'},speed, function() {
	$(this).animate({'margin': '0 -25px 0 25px'},speed, function() {
	$(this).animate({'margin': '0 20px 0 -20px'},speed, function() {
	$(this).animate({'margin': '0 -15px 0 15px'},speed, function() {
	$(this).animate({'margin': '0 10px 0 -10px'},speed, function() {
	$(this).animate({'margin': '0 -5px 0 5px'},speed, function() {
	$(this).animate({'margin':0 },speed, function() {
	// shock end
	});});});});});});});
}

function timeDifference(day1, day2){
    var y1, y2, y3, m1, m2, m3, d1, d2, d3, h1, h2, h3, _m1, _m2, _m3, s1, s2, s3;
    var reg = /年|月|日 |\/|:|-| /;
    //dayinfo -  用正则分割
    var DI1 = day1.split(reg);
    var DI2 = day2.split(reg);

    //var date1 = new Date(DI1[0], parseInt(DI1[1])-1, DI1[2], DI1[3], DI1[4], DI1[5]);
    var date1 = new Date(DI1[0], parseInt(DI1[1])-1, DI1[2]);
    var date2 = new Date(DI2[0], parseInt(DI2[1])-1, DI2[2]);

    //用距标准时间差来获取相距时间
    var minsec = Date.parse(date1) - Date.parse(date2);
    var days = minsec / 1000 / 60 / 60 / 24; //factor: second / minute / hour / day
     
    return days;
}


//弹出一个窗口并加载一个url
function OpenDialog(wd,ht,te,url){
    var thisDiv=$("<div id='OpenDialog'><span id='loadId'><img src='../images/common/loading.gif' /> loading...</span> </div>").appendTo($("BODY"));
    //thisDiv.load(url);
    $.ajax({
    	url: url,
    	type: "get",
    	dataType: "html",
    	contentType: "application/x-www-form-urlencoded;charset=utf-8",
    	timeout:"15000",
    	context: document.body,
    	success: function(data){
    		$("#loadId").hide();
    		thisDiv.append(data);
    	},
    	error: function(){
    		$("#loadId").html("信息加载失败!");
    	}
    });
    
    thisDiv.dialog({
        autoOpen:true,
        width:wd,
        height:ht,
        modal:true,
        resizable:false,
        bgiframe:true,
        title:te,
        close:function(evt,ui){
        	thisDiv.dialog("destroy");
        	thisDiv.html("").remove();
        }
    });
}

//删除前确认
function DelDialog($url){
	MessageDialog($url,"确认删除？","删除后将无法恢复，[确认]进行删除，[取消]返回");
}

function MessageDialog($url,$title,$msg){
    var thisDiv=$("<div style='font-size:12px' id='AlertDialog'>"+$msg+"</div>").appendTo($("BODY"));
    thisDiv.dialog({
        autoOpen:true,
        modal:true,
        resizable:false,
        bgiframe:true,
        title:$title,
        buttons: {
            "确认": function() {window.location.href=$url;},
            "取消": function() {$( this ).dialog( "close" );}
        },
        close:function(evt,ui){
        	thisDiv.dialog("destroy");
        	thisDiv.html("").remove();
        }
    });
}

function AlertDialog($title,$msg){
    var thisDiv=$("<div style='font-size:12px' id='AlertDialog'>"+$msg+"</div>").appendTo($("BODY"));
    thisDiv.dialog({
        autoOpen:true,
        modal:true,
        resizable:false,
        bgiframe:true,
        title:$title,
        buttons: {
            "确认": function() {$( this ).dialog( "close" );}
        },
        close:function(evt,ui){
        	thisDiv.dialog("destroy");
        	thisDiv.html("").remove();
        }
    });
}

function SubmitDialog($title,$msg){
    var thisDiv=$("<div style='font-size:12px' id='SubmitDialog'>"+$msg+"</div>").appendTo($("BODY"));
    thisDiv.dialog({
        autoOpen:true,
        modal:true,
        resizable:false,
        bgiframe:true,
        title:$title,
        buttons: {
            "确认": function() {form.submit();},
            "取消": function() {$( this ).dialog( "close" );}
        },
        close:function(evt,ui){
        	thisDiv.dialog("destroy");
        	thisDiv.html("").remove();
        }
    });
}

function loadpage(){
	var thishash=window.location.hash;
	thishash=thishash.substring(1,thishash.Length);
	//alert(thishash);
	
	//alert(thishash);
	$("#loadpagearea").load("http://zyp:8080/bank_6/custom/"+thishash);
	//re = new RegExp("home#","g");  
	//$loadurl = window.location.href.replace(re, "");
    //$("#loadpagearea").load($loadurl);
}

function showpage(){
	$total=$gettotal==null?1:$gettotal;
	$geturl=window.location.search;
	$link="";
	if($geturl.lastIndexOf("&page=")>=0||($geturl.lastIndexOf("?")>=0&&$geturl.lastIndexOf("?page=")==-1)){
		var aArray =$geturl.split("&page=");
		$link=aArray[0]+"&";
	}else{
		$link="?";
	}
	
	$('.pagebar').bootpag({
		total:$total,page: 1, maxVisible: 10,href:$link+"page={{number}}"
    }).on('page', function(event, num){});
}
//根据利率计算上浮下调
function calcDifferent(num,thisid){
	var str=num>100?"上浮":"下调";
	$(thisid).text(str+Math.abs(num-100)+"%");
}

function selectYearMonth(year ,month){
	var i,j;
	var opyear="";
	var opmonth="";

	for(i=2010;i<2050;i++){
		opyear+="<option value='"+i+"'>"+i+"</option>";				
	}
	for(j=1;j<=12;j++){
		
		opmonth+="<option value='"+j+"'>"+j+"</option>";
	}
	$(year).append(opyear);
	$(month).append(opmonth);
	
	var date = new Date();
    var yy = date.getFullYear();
    $(year).val(yy);
    var mm = date.getMonth();
    $(month).val(mm+1);
    
   // alert(mm.length());
}

function timeCompareTo(start,end){
   	return new Date($(start).val())<new Date($(end).val());
}

//var params = {"username":$("#username").val(),"password":$("#password").val()} 

